package com.card.game;

import com.xiaoao.net.utils.json.GSONUtils;

/**
 * @Description:
 * @author siyunlong
 * @date 2016年8月13日 下午12:11:42
 * @version V1.0
 */
public class Card implements Comparable<Card> {
	private int type = -1;
	private int index = -1;
	private String hurtId;// 新加
	private String lastNum;// 剩余数量
	private transient boolean isOutJin = false;
	private transient boolean isLiujuCard = false;

	public Card(int type, int index) {
		this.type = type;
		this.index = index;
	}

	public void setHurtId(String hurtId) {
		this.hurtId = hurtId;
	}

	public int getType() {
		return type;
	}

	public int getIndex() {
		return index;
	}

	public int getScore() {
		return index == 0 ? 1 : 0;
	}

	public boolean isJianCard() {
		return type == CardType.Jian;
	}

	public int getBingIndex() {
		if (type == CardType.BING) {
			return index;
		}
		return 0;
	}

	// public boolean isNoTingCard() {
	// return index == 1 || index == 2 || index ==3;
	// }
	public boolean isDianpaoCard() {
		return !(index == 3 || index == 4 || index == 5) || type > CardType.BING;
	}

	public boolean isFengCard() {
		return type == CardType.DONG || type == CardType.NAN || type == CardType.XI || type == CardType.BEI;
	}

	// public boolean equals(Object obj) {
	// if (obj == null)
	// return false;
	// Card card = (Card) obj;
	// return this.type == card.type && this.index == card.index;
	// }

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Card other = (Card) obj;
		if (index != other.index)
			return false;
		if (type != other.type)
			return false;
		return true;
	}

	@Override
	public int hashCode() {
		return 0;
	}

	@Override
	public String toString() {
		return GSONUtils.ToJSONString(this);
	}

	@Override
	public int compareTo(Card o) {
		if (this.type == o.type) {
			return this.index - o.index;
		}
		return this.type - o.type;
	}

	public int compareDDzTo(Card o) {
		if (this.equals(o)) {
			return 0;
		}
		if (isJoker() && o.isJoker()) {
			return this.index - o.index;
		}
		if (isJoker()) {
			return 1;
		}
		if (o.isJoker()) {
			return -1;
		}
		if (this.index == o.index) {
			return this.type - o.type;
		}
		return this.index - o.index;
	}

	public static Card getTingCard() {
		return new Card(-1, 0);
	}

	public boolean isOutJin() {
		return isOutJin;
	}

	public void setOutJin(boolean isOutJin) {
		this.isOutJin = isOutJin;
	}

	public boolean isLiujuCard() {
		return isLiujuCard;
	}

	public void setLiujuCard(boolean isLiujuCard) {
		this.isLiujuCard = isLiujuCard;
	}

	public int getNiuIndex() {
		return Math.min(10, index);
	}

	public boolean isJoker() {
		return this.type == 4;
	}

	public boolean isNo2Joker() {
		return this.type != 4 && this.index < 15;
	}

	public boolean isBigJoker() {
		return isJoker() && this.index == 1;
	}

	public boolean isSmallJoker() {
		return isJoker() && this.index == 0;
	}

	public void setLastNum(String lastNum) {
		this.lastNum = lastNum;
	}

	public boolean isHuaCard() {
		// return type == CardType.DONG|| type == CardType.ZHONG|| type == CardType.FA||
		// type == CardType.BAI;
		return false;
	}

	public int getMm() {
		return type * 10 + index;
	}

	public static Card transCard(int c) {
		return new Card(c / 10, c % 10);
	}

	public boolean isJinCard() {
		return this.type == CardType.ZHONG;
	}
}
